package com.ykq.controller;

import com.ykq.entity.Staff;
import com.ykq.service.StaffService;
import com.ykq.vo.LoginVo;
import com.ykq.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

/**
 * @program: keyboard
 * @description:
 * @author: 闫克起2
 * @create: 2023-07-20 15:36
 **/
@RestController
public class LoginController {
    @Autowired
    private StaffService staffService;
    @PostMapping("/login")
    public Result login(@RequestBody LoginVo loginVo, HttpSession session){
        Staff staff = staffService.findByNameAndPwd(loginVo.getUsername(), loginVo.getPassword());
        if(staff==null){
            return new Result(500,"账号或密码错误");
        }
        if(staff.getState()==0){
            return new Result(500,"该账号的员工已离职");
        }
        if(staff.getState()==2){
            return new Result(500,"该账号已被冻结");
        }
        //把当前登录者的信息保存到会话session中: 当作容器:---周期:---只要浏览器不关闭或者服务器不重启--那么该会话就会一致存在。
        session.setAttribute("staff",staff);
        return new Result(200,"登录成功");
    }
}
















